package C30;

import java.util.Arrays;

/**
 * ClassName: C01_Swap
 * Package: C30
 * Description:
 *
 * @Author BCXJ
 * @Create 2024/12/17 14:43
 * @Version 1.0
 * @Since 1.0
 */
public class C01_Swap {
    public static void main(String[] args) {
        int[] arr = {1,2,3,4};
        swap(arr, 0, 2);
        System.out.println(Arrays.toString(arr));
        swap(arr, 0, 0);
        // 交换的位置不能是同一块地址空间，可以相等
        System.out.println(Arrays.toString(arr));
    }
    public static void swap(int[] arr, int a, int b) {
        arr[a] = arr[a] ^ arr[b];
        arr[b] = arr[a] ^ arr[b];
        arr[a] = arr[a] ^ arr[b];
    }
}
